<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* * {
        margin: 0;
        padding: 0;
      } */
      div {
        position: absolute;
        top: 0px;
        left: 0px;
        width: 10px;
        height: 10px;
        background-color: red;
      }
      span {
        position: absolute;
        left: 10px;
        bottom: 10px;
      }
    </style>
  </head>
  <body>
    <div></div>
    <span></span>
  </body>
  <script>
    window.onload = function () {
      var oDiv = document.querySelector("div");
      var oSpan = document.querySelector("span");
      console.log(oDiv.style.position.top);
      document.onmousemove = function (ev) {
        // var x = ev.clientX - oDiv.offsetLeft;
        // var y = ev.clientY - oDiv.offsetTop;
        // var x = ev.clientX;
        // var y = ev.clientY;
        var x = ev.offsetX;
        var y = ev.offsetY;
        oDiv.style.position.top = ev.offsetX + "px";
        console.log(oDiv.style.position.top);
        oDiv.clientHeight = ev.offsetY;
        oSpan.innerHTML = x + "," + y;
      };
      oDiv.onmouseout = function () {
        oSpan.innerHTML = "";
      };
    };
  </script>
</html>
